package com.hk.Mgr.web.controller.remoteCall;

import com.hk.Mgr.web.dto.ProductCopyDTO;
import com.hk.commons.vo.JsonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Antinomy on 17/5/4.
 */
@Service
public class ActivityService {

    @Value("${activity.baseUrl}")
    private String baseUrl;

    private RestTemplate template = new RestTemplate();

    public JsonResult httpGet(String url) {
        JsonResult result = template.getForObject(baseUrl + url, JsonResult.class);
        return result;
    }

    public JsonResult httpPost(String url, Object paramsDto) {
        JsonResult result = template.postForObject(baseUrl + url, paramsDto, JsonResult.class);
        return result;
    }

    public JsonResult copyProductConpons(Long fromProductId, Long toProductId) {
        String url = "api/coupon/productCanUse/copy";

        ProductCopyDTO copyDTO = new ProductCopyDTO();
        copyDTO.setFromProductId(fromProductId);
        copyDTO.setToProductId(toProductId);

        JsonResult result = httpPost(url,copyDTO);
        return result;
    }
}
